Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
@ndhoule/each
Advanced tools
@ndhoule/each is a utility library for iterating over arrays and objects. It provides a simple and consistent way to perform operations on each element of a collection.
Iterate over arrays
This feature allows you to iterate over each element in an array, providing access to both the value and the index of each element.
const each = require('@ndhoule/each');
const array = [1, 2, 3, 4];
each((value, index) => {
console.log(`Index: ${index}, Value: ${value}`);
}, array);
Iterate over objects
This feature allows you to iterate over each property in an object, providing access to both the value and the key of each property.
const each = require('@ndhoule/each');
const object = { a: 1, b: 2, c: 3 };
each((value, key) => {
console.log(`Key: ${key}, Value: ${value}`);
}, object);
Lodash is a modern JavaScript utility library delivering modularity, performance, and extras. It provides a wide range of utility functions, including iteration methods like _.forEach, which can be used to iterate over arrays and objects similarly to @ndhoule/each.
Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. It includes an _.each function that can be used to iterate over arrays and objects, similar to @ndhoule/each.
Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. It includes an async.each function that can be used to iterate over collections asynchronously, offering more advanced control compared to @ndhoule/each.
Iterate over a collection, invoking a function for each element in the collection.
$ component install ndhoule/each
$ npm install @ndhoule/each
each(iterator : Function, collection : Array|Object|string) => undefined
Iterate over an input collection, invoking an iterator
function for each element in the collection, passing to the iterator three arguments: (value, index, collection)
.
The iterator
function can end iteration early by returning false
.
var log = console.log.bind(console);
each(log, ['a', 'b', 'c']);
//-> 'a', 0, ['a', 'b', 'c']
//-> 'b', 1, ['a', 'b', 'c']
//-> 'c', 2, ['a', 'b', 'c']
//=> undefined
each(log, 'tim');
//-> 't', 2, 'tim'
//-> 'i', 1, 'tim'
//-> 'm', 0, 'tim'
//=> undefined
// Note: Iteration order not guaranteed across environments
each(log, { name: 'tim', occupation: 'enchanter' });
//-> 'tim', 'name', { name: 'tim', occupation: 'enchanter' }
//-> 'enchanter', 'occupation', { name: 'tim', occupation: 'enchanter' }
//=> undefined
Released under the MIT license.
2.0.1
FAQs
Iterate over a collection, invoking a function for each element.
The npm package @ndhoule/each receives a total of 178,329 weekly downloads. As such, @ndhoule/each popularity was classified as popular.
We found that @ndhoule/each demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.